import userStore from "~/stores/user";
export const passwordRule =
  /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,16}$/;
export const emailRule = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
export const accountRule = /^([a-zA-Z0-9]){8,16}$/;
export interface LoginType {
  account: string;
  password: string;
}

export class FindLimitDto {
  pageNum?: number = 1;
  pageSize?: number = 10;
  sortBy?: {
    [key: string]: "DESC" | "ASC";
  };
}

export type FindList<T> = {
  list: T[];
  count: number;
};

export const login = async ({ account, password }: LoginType) => {
  //开始请求
  let res = await useServerRequest<{ token: string }>("/auth/login", {
    method: "POST",
    body: {
      account,
      password,
    },
  });
  if (!res?.data.token) return;
  const user = userStore();
  user.token = res?.data.token;
  await navigateTo("/dashboard");
};
